<?php
// Configure the site environment status.
defined('APPLICATION_ENVIRONMENT') or define('APPLICATION_ENVIRONMENT', 'development');

// Invoke the front controller
$frontController = Zend_Controller_Front::getInstance();

// Identify the location of the controller directory
$frontController->setControllerDirectory(APPLICATION_PATH . '/controllers', 'default');

// Create the env parameter so you can later access the environment
// status within the application.
$frontController->setParam('env', APPLICATION_ENVIRONMENT);

// Clean up allocated script resources
unset($frontController);

// Layout Configuration
Zend_Layout::startMvc(APPLICATION_PATH . '/layouts/scripts');
$view = Zend_Layout::getMvcInstance()->getView();
unset($view);

// Configuration file
$GLOBALS["config"] = new Zend_Config_Ini(APPLICATION_PATH.'/config.ini', APPLICATION_ENVIRONMENT);
Zend_Registry::set('config', $GLOBALS["config"]);

//Inizializer helper
//Zend_Controller_Action_HelperBroker::addPath('/Users/antonello/www/ZendTest/application/helper', 'AD');
//$initializer = Zend_Controller_Action_HelperBroker::getStaticHelper('Initializer');
//$randomNumber = $initializer->randomNumber();

//Instantiate the database
$GLOBALS["db"] = Zend_Db::factory('PDO_MySQL', array(
    'host' => $GLOBALS["config"]->database->host,
    'username' => $GLOBALS["config"]->database->username,
    'password' => $GLOBALS["config"]->database->password,
    'dbname' => $GLOBALS["config"]->database->dbname
));
Zend_Db_Table_Abstract::setDefaultAdapter($GLOBALS["db"]);

//Instantiate the languages tool
$GLOBALS["lang"] = new Zend_Translate (
    array(
        'adapter' => 'Ini',
        'content' => 'lang/it.ini',
        'locale'  => 'it'
    )
);
$GLOBALS["lang"]->addTranslation(
    array(
        'content' => 'lang/en.ini',
        'locale' => 'en'
    )
);
$userLanguage = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2);
if($GLOBALS["lang"]->isAvailable($userLanguage)) {
    $GLOBALS["lang"]->setLocale($userLanguage);
}
else $GLOBALS["lang"]->setLocale("en");

//routing
//$router = new Zend_Controller_Router_Rewrite();
//$router->addRoute('content', new Zend_Controller_Router_Route('user/edit/:id'));
?>
